<?php

namespace App\Console\Commands;

use App\Models\Account;
use App\Models\AccountMapping;
use App\Tasks\KeruyunDatasSyncTask;
use App\Tasks\YishengSyncDatasTask;
use Illuminate\Console\Command;

class YishengSyncDatasCmd extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:yisheng-sync-datas-cmd';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $mappings = AccountMapping::query()
            ->with([
                "account",
                "mall",
            ])
            ->from("account_mapping as a")
            ->join("mall as b","a.merchant_no","=","b.merchant_no")
            ->where("a.mall_type",4)
            //->whereIn("a.is_meituan_sync",[1,2])
            //->where("b.merchant_no","40282015")
            ->select("a.*")
            ->get();
        foreach ($mappings as $mapping){
            var_dump($mapping->mall->name);
            $service = new YishengSyncDatasTask($mapping);
            $service->execute();
        }
        $account = Account::query()->where("plamt","ys")->first();
        $account->sync_at = date("Y-m-d H:i:s");
        $account->save();
    }
}
